<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../vue.js"> </script>
</head>
<body>
  <div id="app">
    {{ name }}
    <hr>
    <first-cmp></first-cmp>
    <hr>  
    <first-cmp></first-cmp>
  </div>

  <script>
    /*
    组件里的data是函数返回对象
    在组件复用的时候将数据隔离
    */
    Vue.component("FirstCmp",{
      template: `<h1>
                    123{{name}}
                  <button @click="changeName">改名</button>
                </h1>`,
      data() {
        return {
          name: '组件内的name'
        }
      },
      methods:{
        changeName() {
          this.name = "呵呵哒"
        }
      } 
    })

    new Vue({
      el: "#app", 
      data: {     
        name: "韩梅梅"
      }
    })
  </script>
</body>
</html>